// 如果传入参数直接解构，并设置默认值
const toast = ({ title = "数据加载中...", icon = "none", duration = 2000, mask = true } = {}) => {
    wx.showToast({
        title,
        icon,
        duration,
        mask
    })
}

const modal = (options = {}) => {
    return new Promise((resolve) => {
        // 默认参数
        const defaultOption = {
            title: '提示',
            content: "您确定执行该操作吗？",
            confirmColor: '#f3514f'
        }
        // Object.assign合并默认参数与传递的参数
        const newOption = Object.assign({}, defaultOption, options)
        wx.showModal({
            ...newOption,
            complete: (res) => {
                res.confirm && resolve(true)
                res.cancel && resolve(false)
            }
        })
    })
}

export { toast,modal }